// EquipController.java
package com.geek.hero.controller;

import com.geek.hero.entity.Equip;
import com.geek.hero.result.Result;
import com.geek.hero.service.IEquipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 装备前端控制器
 * </p>
 *
 * @author author
 * @since 2025-09-14
 */
@RestController
@RequestMapping("/equip")
@CrossOrigin
public class EquipController {

    @Autowired
    private IEquipService equipService;

    // 获取所有装备
    @GetMapping
    public Result list() {
        List<Equip> list = equipService.list();
        return new Result(true, "查询成功", list);
    }

    // 根据ID获取装备详情
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Equip equip = equipService.getById(id);
        if (equip != null) {
            return new Result(true, "查询成功", equip);
        } else {
            return new Result(false, "未找到该装备");
        }
    }

    // 根据名称搜索装备
    @GetMapping("/search")
    public Result searchByName(@RequestParam String keyword) {
        List<Equip> equipList = equipService.searchByName(keyword);
        return new Result(true, "查询成功", equipList);
    }
}
